/**
 * @BelongsProject: test
 * @BelongsPackage: com.hmall.order.service.impl
 * @Author: 王明天
 * @CreateTime: 2025/2/19 17:21
 * @Description: OrderServiceImpl
 */
package com.hmall.order.service.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.api.user.UserClient;
import com.hmall.api.user.userDto.User;
import com.hmall.order.domain.Order;
import com.hmall.order.mapper.OrderMapeer;
import com.hmall.order.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderMapeer, Order> implements IOrderService {

    private final UserClient client;

    /**
     * 根据id查询订单
     *
     * @param id
     * @return
     */
    @Override
    public Order getOrderById(Long id) {

        Order order = getById(id);
        if (ObjectUtil.isEmpty(order)){
            throw new RuntimeException("订单不存在");
        }

        order.setUser(client.getUser(order.getUserId()));

        return order;
    }
}
